<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@ include file="/html/init.jsp"%>

<%
	PortletURL saveAddressURL = renderResponse.createActionURL();
	saveAddressURL.setParameter(ActionRequest.ACTION_NAME,"saveAddress");
	List<Country> countries=CountryServiceUtil.getCountries();
	List<Region> regions=RegionServiceUtil.getRegions();
	List<City> cities= null; //CityLocalServiceUtil.getCities(0,-1);
	String homeUrl = themeDisplay.getURLHome();
	long cityNo=0;
	
 
	String popupScript = StringPool.BLANK; 
	PortletURL  shortRegistraion = renderResponse.createRenderURL();
	shortRegistraion.setWindowState(LiferayWindowState.EXCLUSIVE);
	shortRegistraion.setParameter("jspPage", "/html/registration/popup.jsp");
	
	popupScript = "registrationPopup('"+shortRegistraion+"')";

%>

Your Current location: <b><%=location.getFormattedText()%></b>&nbsp;&nbsp; 
    <a href="javascript:void(0);" onclick="<%= popupScript %>">Change	&raquo;</a>
       <%-- <a href="javascript:void(0);" onClick="javascript:<portlet:namespace/>toggleDiv('<portlet:namespace/>newLocation', 'block');">Change	&raquo;</a>
        --%>
 
 <%-- <a href="javascript:void(0);" onclick="<%= popupScript %>">Change	&raquo;</a> --%>

<aui:form action="<%= saveAddressURL %>" name="fm" method="POST">
    <aui:field-wrapper cssClass="registration">
		<aui:column cssClass="aui-w40">
			<div id="<portlet:namespace/>newLocation" style="display: none;">
				<a href="javascript:void(0);"
					onClick="javascript:<portlet:namespace/>toggleDiv('<portlet:namespace/>newLocation', 'none');">
					&laquo; Close</a><br />
					
			<aui:select name="countryId" onchange="getRegions();" label="Country" >
				<aui:option value="" >--Select--</aui:option>
				<%
				    for (Country country : countries) {
				%>
				  <aui:option value="<%=country.getCountryId() %>" selected="<%= (country.getCountryId()==location.getCountryId())?true:false %>">
				  	<%= country.getName()%>
				  </aui:option>
				<%
				  }
				%>
			</aui:select>
			
			
			<aui:select name="regionId" onchange="getCities();" label="Region/State">
				<aui:option value="" >--Select--</aui:option>
				<% 
					regions= RegionServiceUtil.getRegions(location.getCountryId());
			        for (Region region : regions) { 
				%>
				<aui:option value="<%=region.getRegionId()%>" selected="<%= (region.getRegionId()==location.getRegionId())?true:false %>">
					<%= region.getName()%>
				</aui:option>
				<%
			      }
			    %>
			</aui:select>
			
			<%
				cities = CityLocalServiceUtil.getRegion_Cities(location.getRegionId());
				
			%>
			<aui:fieldset id="cities">
				<aui:select name="city"  label="City"   >
				 	<aui:option value="" >--Select--</aui:option>
				 	<%
					   for (City city : cities) { 
					%>
					<aui:option value="<%=city.getCityId()%>"  selected="<%= (city.getCityId()==location.getCityId())?true:false %>">
					<%= city.getCityName()%></aui:option>
					<% } %>
					<aui:option value="<%=cityNo %>" >OTHER CITY</aui:option>
				</aui:select>
			</aui:fieldset>
			<aui:fieldset id="otherCity" >
				<aui:input name="otherCity" type="text" value="<%= location.getCity() %>" label="Enter New City :" />
			</aui:fieldset>
			
			</div>
			<hr/>
			<aui:input name="street1" type="text" label="street1"
				value="<%= location.getStreet1() %>" >
				<aui:validator name="required"/>
			</aui:input>
			
			<aui:input name="street2" type="text" label="street2"
				value="<%= location.getStreet2() %>" />

			<aui:input name="zip" type="text" label="zip"
				value="<%= location.getZip() %>" >
			</aui:input>
			<aui:input type="hidden" name="cityId" value="<%= location.getCityId() %>" />
			<aui:input type="hidden" name="addressId" value="<%= location.getAddressId() %>" />
		</aui:column>
		
		<aui:column cssClass="aui-w60">
			Your IDD Code:  <b>+ <%= location.getIdd() %> </b>
		    <aui:field-wrapper>
			    <aui:input type="hidden" name="primaryPhoneId" value="<%= location.getPrimaryPhoneId() %>" />
			    
				<aui:input type="text" name="primaryPhone" label="Primary Phone" maxlength="10" value="<%= location.getPrimaryPhone() %>" onkeypress="return checkChar(event,/[0-9]/);">
					<aui:validator name="required"/>
				</aui:input>			
				<aui:column> 
					<aui:input cssClass="mobile" checked="<%= true %>" name="isPrimaryMobile" type="checkbox" label="This is a Mobile No." />
				</aui:column>	
			</aui:field-wrapper>
			
			<aui:field-wrapper>
				<aui:input type="hidden" name="secondaryPhoneId" value="<%= location.getSecondaryPhoneId() %>" />
					
				<aui:input type="text" name="secondaryPhone" label="Secondary Phone" maxlength="10" value="<%= location.getSecondaryPhone() %>" onkeypress="return checkChar(event,/[0-9]/);"/>
				<aui:column> 
					<aui:input cssClass="mobile" name="isSecondaryMobile" type="checkbox" label="This is a Mobile No." />
				</aui:column>	
			</aui:field-wrapper>
		</aui:column>
   </aui:field-wrapper>
	
   <aui:button-row>
		<aui:button type="submit" value="Save" href="<%=homeUrl%>"/>
	</aui:button-row>
		<%-- <aui:button type = "button" value = "GO Home" href="<%=homeUrl%>"/> --%>
	
</aui:form>

<aui:script>
 function <portlet:namespace />toggleDiv(divId, show) {
		var div = document.getElementById(divId);
		div.style.display = show;
	}
	

	
 	function checkChar(evt, regExp) {
	   evt = (evt)? evt : window.event;
	
	   var charCode = (evt.which)? evt.which : evt.keyCode;
	
	   if (charCode <= 13 || charCode == 46 || charCode == 39) {
	       return true;
	   } else {
	       var keyChar = String.fromCharCode(charCode);
	       return regExp.test(keyChar);
	   }
   }
   
   
   
   
</aui:script>
<style type="text/css">

.mobile {
	font-size: 10px;
}
.registration .aui-field-input {
	width: 155px;
} 
</style>

<script>
var dialog;
	function registrationPopup(url) {

		var A = AUI();
		var data = {};
		
		AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain', function(A) {
		 dialog = new A.Dialog({
				centered: true,
				destroyOnClose: true,
				draggable: true,
				height: '400',
				width: 400,
				resizable: false,
				modal: true,
				title: Liferay.Language.get('Information'),
			}).render();
				dialog.plug(
					A.Plugin.IO,
					{
						data: data,
						uri: url,
					}
				);
		 });	
	}
	
	</script>
	